package com.wonders.hisdoctor.station.project.allergy.controller;

import com.wonders.his.common.bean.BaseResult;
import com.wonders.his.common.utils.validator.ValidateUtils;
import com.wonders.his.common.utils.validator.group.InsertGroup;
import com.wonders.his.common.utils.validator.group.PrimaryGroup;
import com.wonders.his.common.utils.validator.group.UpdateGroup;
import com.wonders.hisdoctor.station.project.allergy.service.IAllergyService;
import com.wonders.hisdoctor.station.project.base.domain.PatAllergy;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 过敏登记
 *
 * @author zhaogongming
 * @date 2021-03-22
 **/
@Api(tags = "过敏登记")
@RestController
@Validated
@RequestMapping("/allergy")
public class AllergyController {

    @Autowired
    private IAllergyService allergyService;

    @ApiOperation("保存")
    @PostMapping("/save")
    public BaseResult<Integer> save(@RequestBody PatAllergy entity) {
        ValidateUtils.validateEntity(entity, new Class[]{InsertGroup.class});
        return BaseResult.success(allergyService.save(entity));
    }

    @ApiOperation("作废")
    @PostMapping("/delete")
    public BaseResult<Integer> delete(@RequestBody PatAllergy entity) {
        ValidateUtils.validateEntity(entity, new Class[]{PrimaryGroup.class, UpdateGroup.class});
        return BaseResult.success(allergyService.delete(entity));
    }

    @ApiOperation("历史过敏信息")
    @GetMapping("/selectHistory")
    public BaseResult<List<PatAllergy>> selectHistory(@RequestParam(value = "patientId", required = true) String patientId) {
        return BaseResult.success(allergyService.selectHistory(patientId));
    }
}
